var itemlabel;
var DescOfTag = "Description";
var rateNum=0;
var imageId;
var pageURL = window.content.document.location.href;


//control the stars, which indecate the rate level
function saveRate(){
    //get the id number of the star
    var starId;
    rateNum = parseInt(imageId.charAt(4))+1;
    var rateNumber = rateNum.toString();

    //Handle the elements on SideBar
    //get the SideBar first
    //Firefox has a element with id 'sidebar' to access the SideBar
    var sidebar = document.getElementById("sidebar");
    
	 // Verify that our sidebar is open at this moment:
    if (sidebar.contentWindow.location.href =="chrome://nepomuk/content/neposbar.xul")
    {
        //Get the elements on SideBar
        var rateLabel = sidebar.contentDocument.getElementById("SBrateLabel");
		
        //Set the SideBar with the values
        rateLabel.setAttribute("tooltiptext", rateNumber);

        var i = 0;
        for (i = 0; i < 10; i++){
            var starFileName = "star";
			
            if (i < rateNum)
                starFileName += "Light";
            else
                starFileName += "Dark";
		
            if (i % 2 == 0)
                starFileName += "L";
            else
                starFileName += "R";
			
            var starId = "SBstar"+i.toString();
            var starImg = sidebar.contentDocument.getElementById(starId);
            starImg.setAttribute('src', 'chrome://nepomuk/content/images/'+starFileName+'.png');
        }
    }
    //save the rate
    //The rate number in Nepomuk is a single char string. Do a convertion first.
    var pageURL = window.content.document.location.href;
    //alert(pageURL);
    event_handler = Components.classes["@mozilla.org/EventHandlers;1"].getService(Components.interfaces.nsIEventHandlers);
		
    event_handler.saveRating(pageURL, rateNumber, document, window);
    event_handler.refreshPageInfo(pageURL, document);
}


function showDetail(){
    window.openDialog("chrome://nepomuk/content/showdetails.xul","dlg","",itemlabel);
}


function removeComment(){
    var pageURL = window.content.document.location.href;
    
    event_handler = Components.classes["@mozilla.org/EventHandlers;1"].getService(Components.interfaces.nsIEventHandlers);
		
    event_handler.rmComment(pageURL, document);
    event_handler.refreshPageInfo(pageURL, document);
}


